/*
 * #%L
 * java model
 * %%
 * Copyright (C) 2009 - 2011 prefabware.com Stefan Isele
 * %%
 * All Rights Reserved.
 * This program is dual-licensed under the GNU General Public license
 * or a commercial license.
 * You may select to use one or the other of these licenses.
 * To obtain a commercial license please contact Stefan Isele at www.stefan-isele.de
 * Any modifications to this file must keep this entire header intact.
 * Redistribution, except as permitted by the selected license, is prohibited.
 * #L%
 */
package com.prefabware.jmodel.code;

import java.math.BigDecimal;
import java.util.List;

import com.prefabware.commons.CollectionUtil;
import com.prefabware.commons.collection.Gettable;

public class JCodables {
	public static JCodable asCode(final BigDecimal value) {
		return new JCodableBase() {

			@Override
			public String asCode(JCodeOptions options) {
				return String.format("new java.math.BigDecimal(\"%s\")", value);
			}
		};
	}

	public static JCodable asCode(final Float value) {
		return new JCodableBase() {

			@Override
			public String asCode(JCodeOptions options) {
				return String.format("%sF", value);
			}
		};
	}

	public static JCodable asCode(final Short value) {
		return new JCodableBase() {

			@Override
			public String asCode(JCodeOptions options) {
				return String.format("(short)%s", value);
			}
		};
	}

	public static Object asCode(final Long value) {
		return new JCodableBase() {

			@Override
			public String asCode(JCodeOptions options) {
				return String.format("%sL", value);
			}
		};
	}

	/**
	 * @param list
	 * @param options
	 * @return a list of String containing the code for the given JCodables
	 */
	public static List<String> getAsCode(List<JCodable> list, final JCodeOptions options) {
		Gettable<String, JCodable> gettable = new Gettable<String, JCodable>() {

			@Override
			public String get(JCodable from) {
				return from.asCode(options);
			}
		};
		return CollectionUtil.getList(gettable, list);
	}
}
